package com.mysoft.gfyx.common.util;

import com.mysoft.framework.context.api.ContextManager;
import com.mysoft.framework.sdk.system.dto.ActionRightInfoDTO;
import com.mysoft.framework.sdk.system.function.impl.RemoteSystemServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;
import java.util.UUID;

@Component
public class PermUtil {

    @Autowired
    private ContextManager contextManager;

    @Autowired
    private RemoteSystemServiceImpl remoteSystemServiceImpl;

    public String clueActionCode = "020200";

    public String marketActionCode = "010500";

    public List<ActionRightInfoDTO> actions;

    public Boolean checkBusinessUnit(String actionCode) {
        boolean isEnable = false;

        UUID userId = contextManager.fetchContextInfo().getUserContext().getUserId();
        this.actions = remoteSystemServiceImpl.getUserActionRightInfos(userId.toString());

        for (ActionRightInfoDTO action : this.actions) {
            if (Objects.equals(action.getActionCode(), actionCode)) {
                isEnable = true;
                break;
            }
        }

        return isEnable;
    }
}
